package com.wiim.handler;

import java.io.Serializable;

import com.wiim.nhapnhap.EgoodApp;
import com.wiim.processor.SHOPProcessor;

import android.os.Bundle;

public class SHOPCmdHandler extends BaseCmdHandler {

	public final static int COMMAND_INIT_APP = 901;
	public final static int COMMAND_GET_SHOPLIST_BY_CATEGORYID = 402;
	public final static int COMMAND_GET_SHOP_BY_QRCODE = 403;
	public final static int COMMAND_DO_POINTSTRANSACTION = 404;
	public final static int COMMAND_GET_GET_EXCHANGEAWARD_LIST = 405;
	public final static int COMMAND_GET_TRANSACTION_HISTORY_LIST = 406;

	@Override
	public Bundle commandHandler(int command, Bundle cmdData) {
		SHOPProcessor connector = new SHOPProcessor();

		Bundle resultData = new Bundle();

		Object result = null;

		switch (command) {

		case COMMAND_INIT_APP:
			break;

		case COMMAND_GET_SHOPLIST_BY_CATEGORYID: {
			String categoryid = cmdData.getString(EgoodApp.REST_OBJECT_PUT);		
			result = connector.getShopList(categoryid);
			resultData.putSerializable(EgoodApp.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_GET_SHOP_BY_QRCODE: {
			String qrcode = cmdData.getString("qrcode");
			String shopid = cmdData.getString("shopid");
			
			result = connector.getShopDetailByQrcodeOrShopId(qrcode,shopid);
			resultData.putSerializable(EgoodApp.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_DO_POINTSTRANSACTION: {
			
			String transactiontype = cmdData.getString("transactiontype");
			
			String userid = cmdData.getString("userid");
			String fullname = cmdData.getString("fullname");
			
			String shopid = cmdData.getString("shopid");
			String shopname = cmdData.getString("shopname");
			
			String rewardid = cmdData.getString("rewardid");
			String exchangeawardid = cmdData.getString("exchangeawardid");			
			
			String verifycode = cmdData.getString("verifycode");
						
			result = connector.addRewardPoints(transactiontype, userid, fullname, shopid, shopname, rewardid, exchangeawardid, verifycode);
			resultData.putString(EgoodApp.REST_OBJECT_RETURN, (String) result);
		}
			break;
			
		case COMMAND_GET_GET_EXCHANGEAWARD_LIST: {			
			result = connector.getExchangeAwardList();
			resultData.putSerializable(EgoodApp.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_GET_TRANSACTION_HISTORY_LIST: {
			String userid = cmdData.getString(EgoodApp.REST_OBJECT_PUT);		
			result = connector.getTransactionHistoryByUserid(userid);
			resultData.putSerializable(EgoodApp.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;

		default:
			break;
		}

		return resultData;
	}
}
